package fpt.edu.vn.action;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

import fpt.edu.vn.dao.TopicsDao;
import fpt.edu.vn.dao.UsersDao;
import fpt.edu.vn.model.Topics;

/* 
 * DetailAction.java 
 *  
 * 0.1
 * 
 * 10/15/2012 
 *  
 * Copyright notice 
 *  
 * Modification Logs: 
 *   DATE        AUTHOR      DESCRIPTION 
 *  -------------------------------------------------------- 
 *  15-Oct-2012  ThuongND    Create new 
 */
public class DeleteFavAction extends ActionSupport {

	private static final long serialVersionUID = 1L;
	private int topicId;
	private TopicsDao dao = new TopicsDao();
	private UsersDao userdao = new UsersDao();
	private List<Topics> ownerFavorite;
	private int userId;
	public DeleteFavAction() {

	}

	// For SessionAware
	Map<String, Object> session;

	

	public String execute() {
		String email = "";
		session = ActionContext.getContext().getSession();
		if (session.containsKey("emailss")) {
			email = (String) session.get("emailss");
			userId = (Integer) session.get("userIdss");
			if(topicId==-1){
				dao.deleteAllTopicFav(userId);
			}else{
				dao.deletedTopicFav(topicId);
			}
			this.ownerFavorite = userdao.listOwnerFavorite(userId);
		}
		
		return SUCCESS;

	}
	public int getTopicId() {
		return topicId;
	}
	public void setTopicId(int topicId) {
		this.topicId = topicId;
	}
	public List<Topics> getOwnerFavorite() {
		return ownerFavorite;
	}

	public void setOwnerFavorite(List<Topics> ownerFavorite) {
		this.ownerFavorite = ownerFavorite;
	}

	public int getUserId() {
		return userId;
	}

	public void setUserId(int userId) {
		this.userId = userId;
	}
	
	
}
